# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=swig
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.0.12
pkgrel=1
pkgdesc="Generate scripting interfaces to C/C++ code (mingw-w64)"
arch=('any')
url="http://www.swig.org/"
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-pcre")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-lua"
             "${MINGW_PACKAGE_PREFIX}-ruby")
source=(https://downloads.sourceforge.net/${_realname}/${_realname}-${pkgver}.tar.gz
        001-relocate.patch
        002-fix-python-find.patch)
sha256sums=('7cf9f447ae7ed1c51722efc45e7f14418d15d7a1e143ac9f09a668999f4fc94d'
            'b620efcd725546ed74ade96c26b56c4709fc34af3394d8419159ef2cdcc39036'
            '360df7813522ab9f3a56588032b8e33b6396a9f3e61a3d08909bd42bb63dd5fe')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-relocate.patch
  patch -p1 -i ${srcdir}/002-fix-python-find.patch

  ./autogen.sh
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
  ../${_realname}-${pkgver}/configure\
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --without-perl5 \
    --without-guile
  make
}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
  install -D -m644 ${srcdir}/${_realname}-${pkgver}/LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/${_realname}/LICENSE
  install -D -m644 ${srcdir}/${_realname}-${pkgver}/LICENSE-UNIVERSITIES "${pkgdir}${MINGW_PREFIX}"/share/licenses/${_realname}/LICENSE-UNIVERSITIES
}
